class FavoritesController < ApplicationController
  filter_access_to :all

  def create
    new_fav = Favorite.new
    new_fav.item_id = params[:id]
    new_fav.item_type = params[:type]
    new_fav.favorite_list = current_user.default_favorites_list.first
   
    if new_fav.save
      flash[:notice] = 'Added to favorites'
      redirect_to_request_uri
    end

  end

  def destroy
    fav = Favorite.find(params[:id])
    #fav = current_user.favorites.find(:first, 
    #                                  :conditions => ['item_id = ? AND item_type = ?',
    #                                                   params[:id], params[:type]] )
    fav.destroy

    flash[:notice] = 'Removed from favorites'
    redirect_to_request_uri
  end

end
